﻿#define _CRT_SECURE_NO_WARNINGS 1

//给你一个整数n，输出n∗n的蛇形矩阵。

#include<stdio.h>

int main()
{
    int n = 0;
    scanf("%d", &n);
    int k = 0;
    int arr[10][10] = { 0 };
    int pos = 1;
    arr[0][0] = 1;
    int i = 0;
    int j = 0;
    for (int k = 2; k <= n * n; k++)
    {
        if (i == 0 && j < n - 1 && pos == 1)
        {
            arr[i][++j] = k;
            pos = -1;
        }
        else if (j == 0 && i < n - 1 && pos == -1)
        {
            arr[++i][j] = k;
            pos = 1;
        }
        else if (j == n - 1 && pos == 1)
        {
            arr[++i][j] = k;
            pos = -1;
        }
        else if (i == n - 1 && pos == -1)
        {
            arr[i][++j] = k;
            pos = 1;
        }
        else if (pos == -1)
        {
            arr[++i][--j] = k;
        }
        else if (pos == 1)
        {
            arr[--i][++j] = k;
        }
    }
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            printf("%d ", arr[i][j]);
        }
        printf("\n");
    }

    return 0;
}